package cn.tedu.online.day02;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class IteratorDemo {
    public static void main(String[] args) {
        List<Object> list = new ArrayList<>();
        list.add("tom");
        list.add("tom");
        list.add("tom");
        list.add("tom");


        Iterator<Object> iterator = list.iterator();
        List<Object> tmp = new ArrayList<>();
        int i =0;
        while(iterator.hasNext()){
            Object ele = iterator.next();
            if (!tmp.contains(ele)){
                tmp.add(ele);
            }
            else {
                iterator.remove();
            }
        }
        for (Object o : list)
        System.out.println(o);

    }
}
